{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Cells with Odd Values in a Matrix"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #math #simulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #数学 #模拟"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: oddCells"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #奇数值单元格的数目"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个 <code>m x n</code> 的矩阵，最开始的时候，每个单元格中的值都是 <code>0</code>。</p>\n",
    "\n",
    "<p>另有一个二维索引数组 <code>indices</code>，<code>indices[i] = [ri, ci]</code> 指向矩阵中的某个位置，其中 <code>ri</code> 和 <code>ci</code> 分别表示指定的行和列（<strong>从 <code>0</code> 开始编号</strong>）。</p>\n",
    "\n",
    "<p>对 <code>indices[i]</code> 所指向的每个位置，应同时执行下述增量操作：</p>\n",
    "\n",
    "<ol>\n",
    "\t<li><code>r<sub>i</sub></code> 行上的所有单元格，加 <code>1</code> 。</li>\n",
    "\t<li><code>c<sub>i</sub></code> 列上的所有单元格，加 <code>1</code> 。</li>\n",
    "</ol>\n",
    "\n",
    "<p>给你 <code>m</code>、<code>n</code> 和 <code>indices</code> 。请你在执行完所有 <code>indices</code> 指定的增量操作后，返回矩阵中 <strong>奇数值单元格</strong> 的数目。</p>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<p><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/11/06/e1.png\" style=\"height: 118px; width: 600px;\" /></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>m = 2, n = 3, indices = [[0,1],[1,1]]\n",
    "<strong>输出：</strong>6\n",
    "<strong>解释：</strong>最开始的矩阵是 [[0,0,0],[0,0,0]]。\n",
    "第一次增量操作后得到 [[1,2,1],[0,1,0]]。\n",
    "最后的矩阵是 [[1,3,1],[1,3,1]]，里面有 6 个奇数。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<p><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/11/06/e2.png\" style=\"height: 150px; width: 600px;\" /></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>m = 2, n = 2, indices = [[1,1],[0,0]]\n",
    "<strong>输出：</strong>0\n",
    "<strong>解释：</strong>最后的矩阵是 [[2,2],[2,2]]，里面没有奇数。\n",
    "</pre>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 <= m, n <= 50</code></li>\n",
    "\t<li><code>1 <= indices.length <= 100</code></li>\n",
    "\t<li><code>0 <= r<sub>i</sub> < m</code></li>\n",
    "\t<li><code>0 <= c<sub>i</sub> < n</code></li>\n",
    "</ul>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>进阶：</strong>你可以设计一个时间复杂度为 <code>O(n + m + indices.length)</code> 且仅用 <code>O(n + m)</code> 额外空间的算法来解决此问题吗？</p>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [cells-with-odd-values-in-a-matrix](https://leetcode.cn/problems/cells-with-odd-values-in-a-matrix/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [cells-with-odd-values-in-a-matrix](https://leetcode.cn/problems/cells-with-odd-values-in-a-matrix/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['2\\n3\\n[[0,1],[1,1]]', '2\\n2\\n[[1,1],[0,0]]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows = [0] * m\n",
    "        cols = [0] * n\n",
    "        for x, y in indices:\n",
    "            rows[x] = 1 - rows[x]\n",
    "            cols[y] = 1 - cols[y]\n",
    "        return sum(row ^ col for row in rows for col in cols)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows = [0] * m \n",
    "        cols = [0] * n \n",
    "        for x , y in indices:\n",
    "            rows[x] += 1 \n",
    "            cols[y] += 1 \n",
    "        return sum((row + col)&1 for row in rows for col in cols)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rs = [0] * m\n",
    "        cs = [0] * n\n",
    "        for r_c in indices:\n",
    "            r,c = r_c[0],r_c[1]\n",
    "            rs[r] += 1\n",
    "            cs[c] += 1\n",
    "        ri,ci = 0,0\n",
    "        for r in rs:\n",
    "            if r % 2 == 1:\n",
    "                ri += 1\n",
    "        for c in cs:\n",
    "            if c % 2 == 1:\n",
    "                ci += 1\n",
    "        return ri * n + ci * m - 2 * ri * ci"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows, cols = [0] * m, [0] * n\n",
    "        for r, c in indices:\n",
    "            rows[r] ^= 1\n",
    "            cols[c] ^= 1\n",
    "        return (r := sum(rows)) * n + (c := sum(cols)) * m - 2 * r * c\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        res = 0\n",
    "        row = [False] * m\n",
    "        col = [False] * n\n",
    "        for r,c in indices:\n",
    "            row[r] = not row[r]\n",
    "            col[c] = not col[c]\n",
    "        r_cou = Counter(row)\n",
    "        c_cou = Counter(col)\n",
    "        res = r_cou[True] * c_cou[False] + r_cou[False] * c_cou[True]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows = [0] * m\n",
    "        cols = [0] * n\n",
    "        for x, y in indices:\n",
    "            rows[x] = 1 - rows[x]\n",
    "            cols[y] = 1 - cols[y]\n",
    "        return sum(row + col == 1 for row in rows for col in cols)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows, cols = [0] * m, [0] * n\n",
    "        for r, c in indices:\n",
    "            rows[r] ^= 1\n",
    "            cols[c] ^= 1\n",
    "        return (r := sum(rows)) * n + (c := sum(cols)) * m - 2 * r * c\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        r, c = [False] * m, [False] * n\n",
    "        for i, j in indices:\n",
    "            r[i] ^= 1\n",
    "            c[j] ^= 1\n",
    "        a, b = sum(r), sum(c)\n",
    "        return a * (n - b) + (m - a) * b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        r, c = [False] * m, [False] * n\n",
    "        for a, b in indices:\n",
    "            r[a] ^= 1\n",
    "            c[b] ^= 1\n",
    "        oddm, oddn = sum(r), sum(c)\n",
    "        return oddm * (n - oddn) + (m - oddm) * oddn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        row_add =[0]*m\n",
    "        col_add = [0]*n\n",
    "        for r,c in indices:\n",
    "            row_add[r] += 1\n",
    "            col_add[c] += 1\n",
    "        result = 0\n",
    "        for r in range(m):\n",
    "            for c in range(n):\n",
    "                if (row_add[r]+col_add[c])%2==1:\n",
    "                    result += 1\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows = [0] * m\n",
    "        cols = [0] * n\n",
    "\n",
    "        for x,y in indices:\n",
    "            rows[x] += 1\n",
    "            cols[y] += 1\n",
    "        return sum((row + col) % 2 for row in rows for col in cols)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        arr = [[0 for _ in range(n)] for _ in range(m)]\n",
    "        for r, c in indices:\n",
    "            for i in range(n):\n",
    "                arr[r][i] += 1\n",
    "            for j in range(m):\n",
    "                arr[j][c] += 1\n",
    "        ans = 0\n",
    "        for r in range(m):\n",
    "            for c in range(n):\n",
    "                if arr[r][c] % 2 != 0:\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows = [0] * m\n",
    "        cols = [0] * n\n",
    "        for x, y in indices:\n",
    "            rows[x] += 1\n",
    "            cols[y] += 1\n",
    "        return sum((row + col) % 2 for row in rows for col in cols)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        h_row, h_col = [0]*m,[0]*n\n",
    "        for item in indices:\n",
    "            h_row[item[0]] += 1\n",
    "            h_col[item[1]] += 1\n",
    "\n",
    "        res = 0\n",
    "        for i in h_row:\n",
    "            for j in h_col:\n",
    "                if (i+j)%2 == 1:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows = [0] * m\n",
    "        cols = [0] * n\n",
    "        for x, y in indices:\n",
    "            rows[x] += 1\n",
    "            cols[y] += 1\n",
    "        oddx = sum(row % 2 for row in rows)\n",
    "        oddy = sum(col % 2 for col in cols)\n",
    "        return oddx * (n - oddy) + (m - oddx) * oddy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows=[0]*m\n",
    "        cols=[0]*n\n",
    "        for x,y in indices:\n",
    "            rows[x]+=1\n",
    "            cols[y]+=1\n",
    "        oddx=sum(row%2 for row in rows)\n",
    "        oddy=sum(col%2 for col in cols)\n",
    "        return oddx*(n-oddy)+oddy*(m-oddx)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows, cols = [0] * m, [0] * n\n",
    "        for p in indices:\n",
    "            rows[p[0]] += 1\n",
    "            cols[p[1]] += 1\n",
    "        ans = 0\n",
    "        for r in rows:\n",
    "            for c in cols:\n",
    "                if (r + c) % 2:\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        count = 0\n",
    "        ju = [[0 for i in range(n)] for i in range(m)]\n",
    "        for i in indices:\n",
    "            for j in range(n):\n",
    "                ju[i[0]][j] = 1+ju[i[0]][j]\n",
    "            for k in range(m):\n",
    "                ju[k][i[1]] = 1+ju[k][i[1]]\n",
    "        for i in ju:\n",
    "            for j in i:\n",
    "                if j%2!=0:\n",
    "                    count = count+1\n",
    "        return count\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        l1=[0 for i in range(m)]\n",
    "        l2=[0 for i in range(n)]\n",
    "        for indice in indices:\n",
    "            l1[indice[0]]=1+l1[indice[0]]\n",
    "            l2[indice[1]]=1+l2[indice[1]]\n",
    "        cnt=0\n",
    "        for i in range(m):\n",
    "            for j in range(n):\n",
    "                if (l1[i]+l2[j])%2==1:\n",
    "                    cnt+=1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, n: int, m: int, indices: List[List[int]]) -> int:\n",
    "        rows = [0] * n\n",
    "        cols = [0] * m\n",
    "        for x, y in indices:\n",
    "            rows[x] += 1\n",
    "            cols[y] += 1\n",
    "\n",
    "        odd_rows = sum(x % 2 == 1 for x in rows)\n",
    "        odd_cols = sum(y % 2 == 1 for y in cols)\n",
    "        return odd_rows * (m - odd_cols) + (n - odd_rows) * odd_cols"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        matrix = [[0 for _ in range(n)] for _ in range(m)]\n",
    "        for x, y in indices:\n",
    "            for j in range(n):\n",
    "                matrix[x][j] += 1\n",
    "            for row in matrix:\n",
    "                row[y] += 1\n",
    "        return sum(x % 2 for row in matrix for x in row)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows, cols = [0] * m, [0] * n\n",
    "        for x, y in indices:\n",
    "            rows[x] += 1\n",
    "            cols[y] += 1\n",
    "        \n",
    "        oddx = sum(row % 2 for row in rows)\n",
    "        oddy = sum(col % 2 for col in cols)\n",
    "        return oddx * (n - oddy) + (m - oddx) * oddy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        row, column = [0] * m, [0] * n\n",
    "        for i, j in indices:\n",
    "            row[i] ^= 1\n",
    "            column[j] ^= 1\n",
    "        a, b = sum(row), sum(column)\n",
    "        return a * (n - b) + b * (m - a)\n",
    "\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows = [False] * m\n",
    "        cols = [False] * n\n",
    "        for x, y in indices:\n",
    "            rows[x] = not rows[x]\n",
    "            cols[y] = not cols[y]\n",
    "        return sum(row ^ col for row in rows for col in cols)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        r = [0] * m\n",
    "        c = [0] * n\n",
    "        rnum = 0\n",
    "        cnum = 0\n",
    "        for index in indices:\n",
    "            r[index[0]] += 1\n",
    "            if r[index[0]] % 2:\n",
    "                rnum += 1\n",
    "            else:\n",
    "                rnum -=1\n",
    "            c[index[1]] += 1\n",
    "            if c[index[1]] % 2:\n",
    "                cnum += 1\n",
    "            else:\n",
    "                cnum -= 1\n",
    "        return (m - rnum) * cnum + (n - cnum) * rnum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows, cols = [0] * m, [0] * n\n",
    "        for r, c in indices:\n",
    "            rows[r] ^= 1\n",
    "            cols[c] ^= 1\n",
    "        return (r := sum(rows)) * n + (c := sum(cols)) * m - 2 * r * c\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        list1=[]\n",
    "        ans=0\n",
    "        for i in range(m):\n",
    "            row=[]\n",
    "            for j in range(n):\n",
    "                row.append(0)\n",
    "            list1.append(row)\n",
    "        for p in indices:\n",
    "            for q in range(len(list1[p[0]])):\n",
    "                list1[p[0]][q]=list1[p[0]][q]+1\n",
    "            for w in list1:\n",
    "                w[p[1]]=w[p[1]]+1\n",
    "        for z in list1:\n",
    "            for v in z:\n",
    "                if v%2!=0:\n",
    "                    ans=ans+1          \n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        matrix = [[0]*n for _ in range(m)] \n",
    "        for row , col in indices :\n",
    "            for i in range(n) :\n",
    "                matrix[row][i] += 1 \n",
    "            for i in range(m) :\n",
    "                matrix[i][col] += 1\n",
    "        print(matrix) \n",
    "        ans = 0 \n",
    "        for row in matrix:\n",
    "            for x in row :\n",
    "                if x & 1 > 0 :\n",
    "                    ans += 1 \n",
    "        return ans  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        a=[0]*m\n",
    "        b=[0]*n\n",
    "        c=d=0\n",
    "        for i in indices:\n",
    "            a[i[0]]+=1\n",
    "            b[i[1]]+=1\n",
    "        for j in a:\n",
    "            if j%2==1:\n",
    "                c+=1\n",
    "        for k in b:\n",
    "            if k %2==1:\n",
    "                d+=1\n",
    "        return c*n+d*m-c*d*2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        count = 0\n",
    "        ju = [[0 for i in range(n)] for i in range(m)]\n",
    "        for i in indices:\n",
    "            for j in range(n):\n",
    "                ju[i[0]][j] = 1+ju[i[0]][j]\n",
    "            for k in range(m):\n",
    "                ju[k][i[1]] = 1+ju[k][i[1]]\n",
    "        for i in ju:\n",
    "            for j in i:\n",
    "                if j%2!=0:\n",
    "                    count = count+1\n",
    "        return count\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows, cols = [0]*m, [0]*n\n",
    "        for r, c in indices:\n",
    "            rows[r] ^= 1\n",
    "            cols[c] ^= 1\n",
    "\n",
    "        return (sr:=sum(rows))*n + (sc:=sum(cols))*m - 2*sr*sc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        matrix = [[0]*n for _ in range(m)]\n",
    "        num = 0\n",
    "        for x,y in indices:\n",
    "            for j in range(n):\n",
    "                matrix[x][j] += 1\n",
    "            for row in matrix:\n",
    "                row[y] += 1\n",
    "        for row in matrix:\n",
    "            for x in row:\n",
    "                if x%2!=0:\n",
    "                    num += 1\n",
    "        return num\n",
    "                \n",
    "                \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        a=[]\n",
    "        x=len(indices)\n",
    "        num=0\n",
    "        for i in range(m):\n",
    "            b=[]\n",
    "            for j in range(n):\n",
    "                b.append(0)\n",
    "            a.append(b)\n",
    "        for i in range(m):\n",
    "            b=[]\n",
    "            for j in range(n):\n",
    "                for z in range(x):\n",
    "                    if indices[z][0]==i:\n",
    "                        a[i][j]=a[i][j]+1\n",
    "                    if j==indices[z][1]:\n",
    "                        a[i][j]=a[i][j]+1\n",
    "                if a[i][j]%2!=0:\n",
    "                    num=num+1\n",
    "        print(a)\n",
    "        return num\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        a = [[0] * n for _ in range(m)] #初始化列表\n",
    "        for i, j in indices:\n",
    "            for k in range(n):\n",
    "                a[i][k] += 1\n",
    "            for k in range(m):\n",
    "                a[k][j] += 1\n",
    "\n",
    "        count=0\n",
    "        for i in range(n):\n",
    "            for j in range(m):\n",
    "                if a[j][i]%2==1:\n",
    "                    count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        matrix = [[0 for _ in range(n)] for _ in range(m)]\n",
    "        for i in indices:\n",
    "            for j in range(len(matrix[0])):\n",
    "                matrix[i[0]][j] += 1\n",
    "            for j in range(len(matrix)):\n",
    "                matrix[j][i[1]] += 1\n",
    "        res = 0\n",
    "        for i in range(len(matrix)):\n",
    "            for j in range(len(matrix[0])):\n",
    "                if matrix[i][j]%2 == 1:\n",
    "                    res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        matix = [[ 0 for i in range(0, n)] for j in range(m)]\n",
    "        for p in indices:\n",
    "            x, y = p[0], p[1]\n",
    "            for i in range(0, m):\n",
    "                matix[i][y] += 1\n",
    "            for j in range(0, n):\n",
    "                matix[x][j] += 1\n",
    "        res = 0\n",
    "        for i in range(0, m):\n",
    "            for j in range(0, n):\n",
    "                if matix[i][j]%2 == 1:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        sum_,a,len_indices=0,0,len(indices)\n",
    "        list_=[[0]*n for _ in range(m)]\n",
    "        while len_indices:\n",
    "            len_indices-=1\n",
    "            for l in range(n):\n",
    "                list_[indices[a][0]][l]+=1\n",
    "            for k in range(m):\n",
    "                list_[k][indices[a][1]]+=1\n",
    "            a+=1\n",
    "        for i in range(m):\n",
    "            for j in range(n):\n",
    "                if list_[i][j]%2==1:\n",
    "                    sum_+=1\n",
    "        return sum_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows, cols = [0] * m, [0] * n\n",
    "        for r, c in indices:\n",
    "            rows[r] ^= 1\n",
    "            cols[c] ^= 1\n",
    "        return (r := sum(rows)) * n + (c := sum(cols)) * m - 2 * r * c\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        matrix = [[0 for _ in range(n)] for _ in range(m)]\n",
    "        for i in indices:\n",
    "            for j in range(len(matrix[0])):\n",
    "                matrix[i[0]][j] += 1\n",
    "            for j in range(len(matrix)):\n",
    "                matrix[j][i[1]] += 1\n",
    "        res = 0\n",
    "        for i in range(len(matrix)):\n",
    "            for j in range(len(matrix[0])):\n",
    "                if matrix[i][j]%2 == 1:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        matrix = [[0 for _ in range(n)] for _ in range(m)]\n",
    "        for indice in indices:\n",
    "            x, y = indice[0], indice[1]\n",
    "            for i in range(m):\n",
    "                matrix[i][y] += 1\n",
    "            matrix[x] = [num + 1 for num in matrix[x]]\n",
    "        return sum(sum([1 if k & 1 else 0 for k in j]) for j in matrix)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        matrix = [[0] * n for _ in range(m)]\n",
    "        for x, y in indices:\n",
    "            for j in range(n):\n",
    "                matrix[x][j] += 1\n",
    "            for row in matrix:\n",
    "                row[y] += 1\n",
    "        return sum(x % 2 for row in matrix for x in row)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        row = [0] * m\n",
    "        col = [0] * n\n",
    "        for x,y in indices:\n",
    "            row[x] += 1\n",
    "            col[y] += 1\n",
    "        cnt1,cnt2 = 0,0\n",
    "        for i in range(m):\n",
    "            if row[i] % 2 == 1:\n",
    "                cnt1 += 1\n",
    "        for i in range(n):\n",
    "            if col[i] % 2 == 1:\n",
    "                cnt2 += 1\n",
    "        return cnt1 * (n - cnt2) + cnt2 * (m - cnt1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows = [0] * m\n",
    "        cols = [0] * n\n",
    "        for indice in indices:\n",
    "            rows[indice[0]] += 1\n",
    "            cols[indice[1]] += 1\n",
    "        res = 0\n",
    "        for row in rows:\n",
    "            for col in cols:\n",
    "                if row + col & 1 == 1:\n",
    "                    res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        arr = [[0] * n for _ in range(m)]\n",
    "        for indice in indices:\n",
    "            r, c = indice[0], indice[1]\n",
    "            for i in range(n):\n",
    "                arr[r][i] += 1\n",
    "            for j in range(m):\n",
    "                arr[j][c] += 1\n",
    "        res = 0\n",
    "        for x in arr:\n",
    "            for y in x:\n",
    "                if y % 2 == 1:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        juzhen=[[0]*n for i in range(m)]\n",
    "        for indics in indices:\n",
    "            r=indics[0]\n",
    "            c=indics[1]\n",
    "            for i in range(n):\n",
    "                juzhen[r][i]=juzhen[r][i]+1\n",
    "            for i in range(m):\n",
    "                juzhen[i][c]=juzhen[i][c]+1\n",
    "        num=0\n",
    "        for i in range(m):\n",
    "            for j in range(n):\n",
    "                if(juzhen[i][j]%2!=0):\n",
    "                    num+=1\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        l = []\n",
    "        for _ in range(m):\n",
    "            l.append([0] * n)\n",
    "        for x, y in indices:\n",
    "            for i in range(n):\n",
    "                l[x][i] = 1 - l[x][i]\n",
    "            for i in range(m):\n",
    "                l[i][y] = 1 - l[i][y]\n",
    "        return sum(sum(a) for a in l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        # 方法一：直接模拟\n",
    "        matrix = [[0] * n for _ in range(m)]\n",
    "        for x, y in indices:\n",
    "            for j in range(n):\n",
    "                matrix[x][j] += 1\n",
    "            for row in matrix:\n",
    "                row[y] += 1\n",
    "        return sum(x % 2 for row in matrix for x in row)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        mat_0 = [[0] * n for _ in range(m)]\n",
    "\n",
    "        for x in indices:\n",
    "            i_target = x[0]\n",
    "            j_target = x[1]\n",
    "\n",
    "            for j in range(n):\n",
    "                mat_0[i_target][j] = mat_0[i_target][j] + 1\n",
    "\n",
    "            for i in range(m):\n",
    "                mat_0[i][j_target] += 1\n",
    "        \n",
    "        cnt = 0\n",
    "        for i in range(m):\n",
    "            for j in range(n):\n",
    "                if mat_0[i][j] % 2 != 0:\n",
    "                    cnt += 1\n",
    "        \n",
    "        return cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        x=[[0 for _ in range(n)] for _ in range(m)]\n",
    "        for i in indices:\n",
    "            for k in range(len(x)):\n",
    "                x[k][i[1]]+=1\n",
    "            for v in range(len(x[0])):                \n",
    "                x[i[0]][v]+=1\n",
    "            #for p in x:\n",
    "            #    print(p)             \n",
    "            #print('-')\n",
    "        count=0\n",
    "        for i in x:\n",
    "            for j in i:\n",
    "                if j%2==1:\n",
    "                    count+=1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        a = []\n",
    "        matrix = [[0] * n for _ in range(m)]\n",
    "        for x, y in indices:\n",
    "            for j in range(n):\n",
    "                matrix[x][j] += 1\n",
    "            for row in matrix:\n",
    "                row[y] += 1\n",
    "        \n",
    "        return sum(x % 2 for row in matrix for x in row)\n",
    "        \n",
    "        #for i in indices:\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        matrix = [[0] * n for _ in range(m)]\n",
    "        for x, y in indices:\n",
    "            for j in range(n):\n",
    "                matrix[x][j] += 1\n",
    "            for row in matrix:\n",
    "                row[y] += 1\n",
    "        return sum(x % 2 for row in matrix for x in row)\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        lst = [[0] * n for _ in range(m)]\n",
    "        for i in range(len(indices)):\n",
    "            for j in range(len(lst)):\n",
    "                lst[j][indices[i][1]] += 1\n",
    "            for l, x in enumerate(lst[indices[i][0]]):\n",
    "                lst[indices[i][0]][l] = x + 1\n",
    "        num = 0\n",
    "        for k in range(m):\n",
    "            for l in range(n):\n",
    "                if lst[k][l] % 2 == 1:\n",
    "                    num += 1\n",
    "        return num\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        arr = [[0 for _ in range(n)] for _ in range(m)]\n",
    "        for r, c in indices:\n",
    "            arr[r][c] += 2\n",
    "            for i in range(c):\n",
    "                arr[r][i] += 1\n",
    "            for i in range(c + 1, n):\n",
    "                arr[r][i] += 1\n",
    "            for j in range(r):\n",
    "                arr[j][c] += 1\n",
    "            for j in range(r + 1, m):\n",
    "                arr[j][c] += 1\n",
    "        ans = 0\n",
    "        for r in range(m):\n",
    "            for c in range(n):\n",
    "                if arr[r][c] % 2 != 0:\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        ans = []\n",
    "        count=0\n",
    "        for i in range(m):\n",
    "            inner = [0] * n\n",
    "            ans.append(inner)\n",
    "\n",
    "        for x, y in indices:\n",
    "            for j in range(n):\n",
    "                ans[x][j]+=1\n",
    "            for i in range(m):\n",
    "                ans[i][y]+=1\n",
    "        # print(ans)\n",
    "        for row in ans:\n",
    "            for j in row:\n",
    "                if j %2==1:\n",
    "                    count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        matrix = [[0] * n for _ in range(m)]\n",
    "        for x, y in indices:\n",
    "            for j in range(n):\n",
    "                matrix[x][j] += 1\n",
    "            for row in matrix:\n",
    "                row[y] += 1\n",
    "        return sum(x % 2 for row in matrix for x in row)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        matrix = [[0] * n for _ in range(m)]\n",
    "        for x, y in indices:\n",
    "            for j in range(n):\n",
    "                matrix[x][j] += 1\n",
    "            for row in matrix:\n",
    "                row[y] += 1\n",
    "        return sum(x % 2 for row in matrix for x in row)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        res = [[0] * n for _ in range(m)]\n",
    "        for x, y in indices:\n",
    "            for i in range(n):\n",
    "                res[x][i] += 1\n",
    "            for j in range(m):\n",
    "                res[j][y] += 1\n",
    "        res1 = 0\n",
    "        for i in res:\n",
    "            for j in i:\n",
    "                if j % 2 == 1:\n",
    "                    res1 += 1\n",
    "        return res1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        a=[]\n",
    "        b=[]\n",
    "        for i in indices:\n",
    "            c,d=i\n",
    "            if c in a:\n",
    "                a.remove(c)\n",
    "            else:\n",
    "                a.append(c)\n",
    "            if d in b:\n",
    "                b.remove(d)\n",
    "            else:\n",
    "                b.append(d)\n",
    "        s,t=len(a),len(b)\n",
    "        return (s*n+t*m-s*t*2)            \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        counter_row, counter_col = Counter([i[0] for i in indices]), Counter([i[1] for i in indices])\n",
    "        res = 0\n",
    "        for i in range(m):\n",
    "            for j in range(n):\n",
    "                res += 0 if (counter_row[i] + counter_col[j]) % 2 == 0 else 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        matrix = [[0] * n for _ in range(m)]\n",
    "        for x, y in indices:\n",
    "            for j in range(n):\n",
    "                matrix[x][j] += 1\n",
    "            for row in matrix:\n",
    "                row[y] += 1\n",
    "        return sum(x % 2 for row in matrix for x in row)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        row, col = [0] * m, [0] * n\n",
    "        for indice in indices:\n",
    "            r, c = indice[0], indice[1]\n",
    "            row[r] += 1\n",
    "            col[c] += 1\n",
    "        row_odd = sum(i % 2 == 1 for i in row)\n",
    "        row_even = m - row_odd\n",
    "        col_odd = sum(i % 2 == 1 for i in col)\n",
    "        col_even = n - col_odd\n",
    "        return row_odd * col_even + row_even * col_odd\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        mat = [[0] * n for _ in range(m)]\n",
    "        # print(\"mat=\", mat)\n",
    "        for indice in indices:\n",
    "            row, col = indice[0], indice[1]\n",
    "            # 行处理\n",
    "            mat[row] = [item+1 for item in mat[row]]\n",
    "            # 列处理\n",
    "            for i in range(m):\n",
    "                mat[i][col] += 1\n",
    "        # print(\"mat=\", mat)\n",
    "        # 查询奇数个数\n",
    "        ans = 0\n",
    "        for i in range(m):\n",
    "            for j in range(n):\n",
    "                if mat[i][j] % 2 == 1:\n",
    "                    ans += 1\n",
    "        return ans\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        row = [0]*m\n",
    "        col = [0]*n\n",
    "        for i, j in indices:\n",
    "            row[i] += 1\n",
    "            col[j] += 1\n",
    "        odd_1 = sum(x%2 for x in row)\n",
    "        odd_2 = sum(x%2 for x in col)\n",
    "        return odd_1*(n-odd_2) + odd_2*(m-odd_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        a = [[0] * n for _ in range(m)]\n",
    "        for x, y in indices:\n",
    "            for i in range(n): #对行加\n",
    "                a[x][i] += 1\n",
    "            for j in range(m): #对列加\n",
    "                a[j][y] += 1\n",
    "        res = 0\n",
    "        for i in range(m):\n",
    "            for j in range(n):\n",
    "                if a[i][j] % 2 == 1:\n",
    "                    res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        mat=[[0 for i in range(n)]for j in range(m)]\n",
    "        for indice in indices:\n",
    "            for i in range(n):\n",
    "                mat[indice[0]][i]=1+mat[indice[0]][i]\n",
    "            for i in range(m):\n",
    "                mat[i][indice[1]]=1+mat[i][indice[1]]\n",
    "        cnt=0\n",
    "        for i in mat:\n",
    "            for j in i:\n",
    "                if j%2==1:\n",
    "                    cnt+=1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        nums = [0]*(m)\n",
    "        nums2 = [0]*n\n",
    "\n",
    "        for x,y in indices:\n",
    "            nums[x] += 1\n",
    "            nums2[y] += 1\n",
    "        ans = 0\n",
    "        print(nums,nums2)\n",
    "        # ma\n",
    "        for i in range(m):\n",
    "            for j in range(n):\n",
    "                if (nums[i] + nums2[j] )%2 == 1:\n",
    "                    ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        nums = [[0 for _ in range(n)] for _ in range(m)]\n",
    "        for each in indices:\n",
    "            x, y = each\n",
    "            for i in range(m):\n",
    "                nums[i][y] += 1\n",
    "            for i in range(n):\n",
    "                nums[x][i] += 1\n",
    "        result = 0\n",
    "        for each_arr in nums:\n",
    "            for each in each_arr:\n",
    "                if each % 2 == 1:\n",
    "                    result += 1\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        arr = [[0 for _ in range(n)] for a in range(m)]\n",
    "        for r, c in indices:\n",
    "            for col in range(n):\n",
    "                arr[r][col] += 1\n",
    "            for row in range(m):\n",
    "                arr[row][c] += 1\n",
    "        \n",
    "        ans = 0\n",
    "        for i in range(m):\n",
    "            for j in range(n):\n",
    "                if (arr[i][j] % 2 == 1):\n",
    "                    ans += 1\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        rows=[0]*m\n",
    "        cols=[0]*n\n",
    "        for indice in indices:\n",
    "            rows[indice[0]]=1-rows[indice[0]]\n",
    "            cols[indice[1]]=1-cols[indice[1]]\n",
    "        r=sum(rows)\n",
    "        c=sum(cols)\n",
    "        return r*(n-c)+c*(m-r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        matrix = [[0]*n for _ in range(m)]\n",
    "        for x,y in indices:\n",
    "            for j in range(n):\n",
    "                matrix[x][j] += 1\n",
    "            for i in range(m):\n",
    "                matrix[i][y] += 1\n",
    "        ans = 0\n",
    "        for r in range(m):\n",
    "            for c in range(n):\n",
    "                if matrix[r][c] % 2 == 1:\n",
    "                    ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        matrix = [[0] * n for _ in range(m)]\n",
    "        for x, y in indices:\n",
    "            for j in range(n):\n",
    "                matrix[x][j] += 1\n",
    "            for row in matrix:\n",
    "                row[y] += 1\n",
    "        return sum(x % 2 for row in matrix for x in row)\n",
    "\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        need_list = [[0] * n for _ in range(m)]\n",
    "        for x in indices:\n",
    "            # 更改行\n",
    "            # print(need_list[x[0]])\n",
    "            for y in range(n):\n",
    "                need_list[x[0]][y] += 1\n",
    "            # 更改列\n",
    "            for z in range(m):\n",
    "                need_list[z][x[1]] += 1\n",
    "        # 结果\n",
    "        result = 0\n",
    "        for i in range(m):\n",
    "            for j in range(n):\n",
    "                if need_list[i][j] % 2 == 1:\n",
    "                    result += 1\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        fy = Counter() \n",
    "        fx = Counter() \n",
    "        for x, y in indices:\n",
    "            fx[x] += 1\n",
    "            fy[y] += 1\n",
    "        mat = [[0] * n for _ in range(m)]\n",
    "        for y, val in fy.items():\n",
    "            for i in range(m):\n",
    "                mat[i][y] += val \n",
    "        for x, val in fx.items():\n",
    "            for j in range(n):\n",
    "                mat[x][j] += val \n",
    "        ans = 0 \n",
    "        for i in range(m):\n",
    "            for j in range(n):\n",
    "                if mat[i][j] % 2 == 1:\n",
    "                    ans += 1\n",
    "        return ans "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        mat = []\n",
    "        for i in range(m):\n",
    "            mat.append([])\n",
    "            for j in range(n):\n",
    "                mat[i].append(0)\n",
    "\n",
    "        for i in range(len(indices)):\n",
    "            for j in range(len(indices[i])):\n",
    "                if j == 0:\n",
    "                    for y in range(n):\n",
    "                        mat[indices[i][j]][y] += 1\n",
    "                else:\n",
    "                    for x in range(m):\n",
    "                        mat[x][indices[i][j]] += 1\n",
    "\n",
    "        cnt = 0\n",
    "        for i in range(m):\n",
    "            for j in range(n):\n",
    "                if mat[i][j] % 2 == 1:\n",
    "                    cnt += 1\n",
    "\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:\n",
    "        mat = []\n",
    "        for i in range(m):\n",
    "            mat.append([])\n",
    "            for j in range(n):\n",
    "                mat[i].append(0)\n",
    "\n",
    "        for i in range(len(indices)):\n",
    "            for j in range(len(indices[i])):\n",
    "                if j == 0:\n",
    "                    for y in range(n):\n",
    "                        mat[indices[i][j]][y] += 1\n",
    "                else:\n",
    "                    for x in range(m):\n",
    "                        mat[x][indices[i][j]] += 1\n",
    "\n",
    "        cnt = 0\n",
    "        for i in range(m):\n",
    "            for j in range(n):\n",
    "                if mat[i][j] % 2 == 1:\n",
    "                    cnt += 1\n",
    "\n",
    "        return cnt"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
